/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Entities;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author anhvh_b00319
 */
@Entity
@Table(name = "SuccessStory")
@NamedQueries({
    @NamedQuery(name = "SuccessStory.findAll", query = "SELECT s FROM SuccessStory s"),
    @NamedQuery(name = "SuccessStory.findByStoryID", query = "SELECT s FROM SuccessStory s WHERE s.storyID = :storyID"),
    @NamedQuery(name = "SuccessStory.findByCreatedDate", query = "SELECT s FROM SuccessStory s WHERE s.createdDate = :createdDate"),
    @NamedQuery(name = "SuccessStory.findByCustomerName", query = "SELECT s FROM SuccessStory s WHERE s.customerName = :customerName"),
    @NamedQuery(name = "SuccessStory.findByStoryName", query = "SELECT s FROM SuccessStory s WHERE s.storyName = :storyName"),
    @NamedQuery(name = "SuccessStory.findByStoryTopic", query = "SELECT s FROM SuccessStory s WHERE s.storyTopic = :storyTopic")})
public class SuccessStory implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "Story_ID")
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer storyID;
    @Basic(optional = false)
    @Column(name = "CreatedDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;
    @Basic(optional = false)
    @Column(name = "Customer_Name")
    private String customerName;
    @Basic(optional = false)
    @Column(name = "Story_Name")
    private String storyName;
    @Basic(optional = false)
    @Column(name = "Story_Topic")
    private String storyTopic;
    @Transient
    private String formatedCreatedDate;

    public SuccessStory() {
    }

    public SuccessStory(Integer storyID) {
        this.storyID = storyID;
    }

    public SuccessStory(Integer storyID, Date createdDate, String customerName, String storyName, String storyTopic) {
        this.storyID = storyID;
        this.createdDate = createdDate;
        this.customerName = customerName;
        this.storyName = storyName;
        this.storyTopic = storyTopic;
    }

    public Integer getStoryID() {
        return storyID;
    }

    public void setStoryID(Integer storyID) {
        Integer oldStoryID = this.storyID;
        this.storyID = storyID;
        changeSupport.firePropertyChange("storyID", oldStoryID, storyID);
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        Date oldCreatedDate = this.createdDate;
        this.createdDate = createdDate;
        changeSupport.firePropertyChange("createdDate", oldCreatedDate, createdDate);
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        String oldCustomerName = this.customerName;
        this.customerName = customerName;
        changeSupport.firePropertyChange("customerName", oldCustomerName, customerName);
    }

    public String getStoryName() {
        return storyName;
    }

    public void setStoryName(String storyName) {
        String oldStoryName = this.storyName;
        this.storyName = storyName;
        changeSupport.firePropertyChange("storyName", oldStoryName, storyName);
    }

    public String getStoryTopic() {
        return storyTopic;
    }

    public void setStoryTopic(String storyTopic) {
        String oldStoryTopic = this.storyTopic;
        this.storyTopic = storyTopic;
        changeSupport.firePropertyChange("storyTopic", oldStoryTopic, storyTopic);
    }

    public String getFormatedCreatedDate() {
        SimpleDateFormat sdf = new SimpleDateFormat("MMM/dd/yyyy");
        formatedCreatedDate = sdf.format(createdDate);
        return formatedCreatedDate;
    }

    public void setFormatedCreatedDate(String formatedCreatedDate) {
        this.formatedCreatedDate = formatedCreatedDate;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (storyID != null ? storyID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SuccessStory)) {
            return false;
        }
        SuccessStory other = (SuccessStory) object;
        if ((this.storyID == null && other.storyID != null) || (this.storyID != null && !this.storyID.equals(other.storyID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entities.SuccessStory[storyID=" + storyID + "]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
